const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: '',
    page: 1,
    loadStatus: false,
    not: false
  },
  // 加载更多
  load() {
    let that = this;
    let page = that.data.page;
    if (that.data.loadStatus) { return; }
    if (that.data.not) { return; }
    that.setData({
      loadStatus: true
    })
    page = ++page;
    wx.showLoading({
      title: '加载更多...',
    })
    wx.request({
      url: app.buildUrl('/user/get-collection'),
      method: 'GET',
      data: {
        page: page,
        status: 0,
        type:0
      },
      header: app.buildHeader(),
      success: function (res) {
        wx.hideLoading()
        if (res.data.code == 200) {
          if (res.data.data.length == 0) {
            app.showToast('没有更多了')
            that.setData({
              not: true
            });
          } else {
            that.setData({
              list: that.data.list.concat(res.data.data),
              page: page
            });
          }
        } else {
          app.showToast(res.data.msg)
        }
        that.setData({
          loadStatus: false
        })
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    wx.showLoading({
      title: '加载更多...',
    })
    wx.request({
      url: app.buildUrl('/user/get-collection'),
      method: 'GET',
      data: {
        page: 1,
        status: 0,
        type:0
      },
      header: app.buildHeader(),
      success: function (res) {
        wx.hideLoading()
        if (res.data.code == 200) {
          that.setData({
            list: res.data.data
          });
        } else {
          app.showToast(res.data.msg)
        }
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  }
})